package com.zsc.boot.exception;

import com.zsc.boot.common.BaseResponse;
import com.zsc.boot.common.ErrorType;
import com.zsc.boot.common.ResultResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse ExceptionHandler(BusinessException e){
        return ResultResponse.error(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse RuntimeException(BusinessException e){
        return ResultResponse.error(ErrorType.SYSTEM_ERROR);
    }
}
